#ifndef SMARTQA_H
#define SMARTQA_H

#include <QWidget>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QSettings>
#include <QListWidgetItem>
#include <QRandomGenerator>

QT_BEGIN_NAMESPACE
namespace Ui { class SmartQA; }
QT_END_NAMESPACE

class SmartQA : public QWidget
{
    Q_OBJECT

public:
    SmartQA(QWidget *parent = nullptr);
    ~SmartQA();

private slots:
    void onAskButtonClicked();
    void onClearButtonClicked();
    void onClearHistoryButtonClicked();
    void onSaveKeyButtonClicked();
    void onHistoryItemClicked(QListWidgetItem *item);
    void onModelChanged(const QString &model);  // 添加模型选择槽函数

    void handleNetworkReply();
    void handleNetworkError();

private:
    Ui::SmartQA *ui;
    QNetworkAccessManager *networkManager;
    QSettings *settings;

    void askQuestion(const QString &question);
    void askQuestionWithOpenRouter(const QString &question);
    void displayAnswer(const QString &answer);
    void addToHistory(const QString &question);
    void saveApiKey(const QString &key);
    QString loadApiKey();
    void updateStatus(const QString &message);
    void setupModelComboBox();  // 添加模型选择下拉框设置

    bool eventFilter(QObject *obj, QEvent *event) override;

    int retryCount;
    const int maxRetries = 3;
};

#endif // SMARTQA_H
